package javase.swing;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class Calculator extends JFrame implements ActionListener
{
	String str[]={"1","2","3","+","4","5","6","-","7","8","9","*","0",".","=","/"};
	JTextField jtf;
	public Calculator()
	{
		this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		Container c=this.getContentPane();
		jtf=new JTextField();
		jtf.setHorizontalAlignment(JTextField.RIGHT);
		JPanel jpl=new JPanel();
		jpl.setLayout(new GridLayout(4,4));
		JButton[] b=new JButton[16];
		for(int i=0;i<16;i++)
		{
			b[i]=new JButton(str[i]);
			b[i].addActionListener(this);
			jpl.add(b[i]);
		}
		c.add(jtf,"North");
		c.add(jpl,"Center");
	}
	public void actionPerformed(ActionEvent ae)
	{
		jtf.setText(jtf.getText()+ae.getActionCommand());
	}
	public static void main(String[] args)
	{
		Calculator c=new Calculator();
		c.setSize(400,300);
		c.setVisible(true);
	}
}
